{% extends "base.html" %}

{% load static %}

{% block content %}
    <div class="goods_type">
        <div class="goods_details"><a href="#">首页</a> >{{ goods_obj.goods_name }}</div>
        <div class="goods_box">
            <div class="box_pic"><img src="{% static goods_obj.image_set.first.img_address.name %}"/></div>
            <div class="box_details">
                <form method="post" action="/Buyer/car_jump/?id={{ goods_obj.id }}">
                    {% csrf_token %}
                    <h1>{{ goods_obj.goods_name }}</h1>
                    <span style='font-size: 15px;'>{{ goods_obj.goods_description|safe }}</span>

                    <div class="box_bg">
                        价格：￥<span class="price_span">
                        {{ goods_obj.goods_cprice }}</span>
                        元&nbsp;&nbsp;原价:￥<s style='color: #ff0000'> {{ goods_obj.goods_oprice }}</s></div>
                    <div class="address">配送:  顺丰快递</div>
                    <div class="address">存储方:  适宜的环境</div>
                    <div class="address">库存:  {{ goods_obj.goods_kucun }}</div>

                    <div class="num">数量：
                        <input type="button" name="-" value="-" class="btn1" onclick="dec()"/>
                        <input type="text" value="1" id="count" name="count" class="text1"/>
                        <input type="button" name="+" value="+" class="btn1" onclick="add()"/>
                    </div>
                    {#携带商品名称 到购物车中间页面#}
                    <input type="hidden" name="goods_name" value="{{ goods_obj.goods_name }}">
                    {#携带商品价格 到购物车中间页面#}
                    <input type="hidden" name="goods_cprice" value="{{ goods_obj.goods_cprice }}">
                    {#添加购物车携带图片#}
                    <input type="hidden" name="goods_img_path" value="{{ goods_obj.image_set.first.img_address.name }}">
                    <div class="btn2"><input type="submit" value="加入购物车" class="gouwu"/></div>
                </form>
            </div>
            <div class="goods_heat_big_div">
                <div class="goods_heat_big_title">商品热度</div>
                <div class="goods_heat_title">销售量:{{ goods_obj.goods_sales }}</div>
                <div class="goods_heat_title">评论量:{{ goods_comment_list.count }}</div>
                <div class="goods_heat_title">浏览量:{{ goods_obj.goods_browses }}</div>
                <div class="goods_heat_title">收藏量:{{ goods_collect_list.count }}</div>
                <a href="/Buyer/goods_collection/?id={{ goods_obj.id }}&collect_state=1" class="goods_a1">我要收藏</a>
                <a href="/Buyer/goods_collection/?id={{ goods_obj.id }}&collect_state=0" class="goods_a2">取消收藏</a>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        var count;

        function add() {
            count = document.getElementById('count').value;

            var xiancun = document.getElementById('count').value;
            var kucun1 = {{ goods_obj.goods_kucun }}
            if (xiancun >= kucun1 ) {
                alert("库存为:" + {{ goods_obj.goods_kucun }}+ ",您已经超出库存！")
                document.getElementById('count').value = {{ goods_obj.goods_kucun }}
            }
            else {
                count++;
                document.getElementById('count').value = count;
            }

        }

        function dec() {
            count = document.getElementById('count').value;
            count--;
            if (document.getElementById('count').value <= 1) {
                document.getElementById('count').value = 1
            }
            else {
                document.getElementById('count').value = count;
            }
        }
    </script>
    <div class="goods_type1">
        <div class="type1_left">
            <div class="type1_top">其他商品</div>
            <div class="type1_bottom">

                {% for goods_obj in goods_list %}
                    <a href="/Buyer/goods_details/?id={{ goods_obj.id }}">
                        <dl>
                            <dt><img src="{% static goods_obj.image_set.first.img_address.name %}"/></dt>
                            <dd>
                                <span class="pname">
                                    {{ goods_obj.goods_name }}
                                </span>
                                <p class="price">￥{{ goods_obj.goods_cprice }}</p>
                            </dd>
                        </dl>
                    </a>
                {% endfor %}

            </div>
        </div>

        <div class="goods_details_div">
            <form method="post" action="/Buyer/goods_details/">
                {% csrf_token %}
                <input type="hidden" name="spxq" value="商品详情">
                <input type="hidden" name="id" value="{{ goods_obj.id  }}">
                <input type="submit" value="商品详情" class="type1_top"/>
            </form>
        </div>

        <div class="goods_details_div">
            <form method="post" action="/Buyer/goods_comments/">
                {% csrf_token %}
                <input type="hidden" name="sppl" value="商品评论">
                <input type="hidden" name="id" value="{{ goods_obj.id  }}">
                <input type="submit" value="商品评论" class="type1_top"/>
            </form>

        </div>

        <div class="types_div">

            <div class="type1_bottom">
                {{ goods_obj.goods_details|safe }}
            </div>

        </div>
    </div>

{% endblock %}